package biz.obake.team.touchprotector.lfd;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import biz.obake.team.touchprotector.lfd.c;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class d {

    /* renamed from: d  reason: collision with root package name */
    private static d f1737d;
    /* access modifiers changed from: private */

    /* renamed from: a  reason: collision with root package name */
    public ArrayList<c> f1738a = new ArrayList<>();

    /* renamed from: b  reason: collision with root package name */
    private c f1739b;

    /* renamed from: c  reason: collision with root package name */
    private List<b> f1740c = new ArrayList();

    public interface b {
        void onLfdPackageManagerChanged();
    }

    private class c extends AsyncTask<Void, c, Void> {

        /* renamed from: a  reason: collision with root package name */
        ArrayList<c> f1741a;

        private c() {
            this.f1741a = new ArrayList<>();
        }

        private boolean b() {
            if (d.this.f1738a.size() != this.f1741a.size()) {
                return false;
            }
            Iterator it = d.this.f1738a.iterator();
            boolean z = false;
            while (it.hasNext()) {
                String j = ((c) it.next()).j();
                Iterator<c> it2 = this.f1741a.iterator();
                while (true) {
                    if (it2.hasNext()) {
                        if (j.equals(it2.next().j())) {
                            z = true;
                            continue;
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (!z) {
                    return false;
                }
            }
            return true;
        }

        /* access modifiers changed from: protected */
        /* renamed from: a */
        public Void doInBackground(Void... voidArr) {
            for (PackageInfo next : biz.obake.team.android.a.a().getPackageManager().getInstalledPackages(0)) {
                if (isCancelled()) {
                    return null;
                }
                try {
                    this.f1741a.add(new c(next.packageName));
                } catch (PackageManager.NameNotFoundException | c.b unused) {
                }
            }
            return null;
        }

        /* access modifiers changed from: protected */
        /* renamed from: c */
        public void onPostExecute(Void voidR) {
            if (!isCancelled() && !b()) {
                ArrayList unused = d.this.f1738a = this.f1741a;
                d.this.f();
            }
        }
    }

    public static d d() {
        if (f1737d == null) {
            f1737d = new d();
        }
        return f1737d;
    }

    /* access modifiers changed from: private */
    public void f() {
        for (b onLfdPackageManagerChanged : this.f1740c) {
            onLfdPackageManagerChanged.onLfdPackageManagerChanged();
        }
    }

    public c[] e() {
        return (c[]) this.f1738a.toArray(new c[0]);
    }

    public void g(b bVar) {
        if (!this.f1740c.contains(bVar)) {
            this.f1740c.add(bVar);
        }
    }

    public void h() {
        c cVar = this.f1739b;
        if (cVar != null) {
            cVar.cancel(true);
        }
        c cVar2 = new c();
        this.f1739b = cVar2;
        cVar2.execute(new Void[0]);
    }

    public void i(b bVar) {
        if (this.f1740c.contains(bVar)) {
            this.f1740c.remove(bVar);
        }
    }
}
